package edu.gyc.swing.test;

import java.io.File;
import java.io.FilenameFilter;
import java.util.*;

public class HiSort {
    public static void main(String[] args) {
        File file = new File("k:/girls/21487");
        String[] names=file.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                if (name.endsWith("jpg") || name.endsWith("jpeg")) {
                    return true;
                }
                return false;
            }
        });
        List<String> nameList = Arrays.asList(names);
        Random random = new Random();
        boolean flag=false;


        System.out.println(nameList);
        Collections.sort(nameList);
        System.out.println(nameList);
        Collections.sort(nameList, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int i = extractNumber(o1);
                int j = extractNumber(o2);

                return i-j;
            }
        });
        System.out.println(nameList);
    }

    private static int extractNumber(String name) {
        int i;
        try {
            String number = name.replaceAll("[^\\d]", "");
            i = Integer.parseInt(number);
        } catch (Exception e) {
            i = 0;
        }
        return i;
    }

}
